<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">



<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css">


  <meta name="keywords" content="笔记,汇编,">








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0">






<meta name="description" content="更灵活的定位内存地址的方法汇编大小写转换12345678910111213141516171819202122232425262728assume cs:code,ds:datadata segmentdb &apos;BaSiC&apos; ;把这个字符串全部变为大写db &apos;iNfOrMaTiOn&apos; ;把这个字符串全部变为小写data endscode segmentstart:  mov ax,data	 ;获取">
<meta name="keywords" content="笔记,汇编">
<meta property="og:type" content="article">
<meta property="og:title" content="更灵活的定位内存地址的方法">
<meta property="og:url" content="http://blog.vimc.cc/2017/08/21/灵活的定位内存地址/index.html">
<meta property="og:site_name" content="你的口袋有什么？">
<meta property="og:description" content="更灵活的定位内存地址的方法汇编大小写转换12345678910111213141516171819202122232425262728assume cs:code,ds:datadata segmentdb &apos;BaSiC&apos; ;把这个字符串全部变为大写db &apos;iNfOrMaTiOn&apos; ;把这个字符串全部变为小写data endscode segmentstart:  mov ax,data	 ;获取">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://oqca0721d.bkt.clouddn.com/wwtpxy1503303934.png">
<meta property="og:image" content="http://oqca0721d.bkt.clouddn.com/bj264i1503359790.png">
<meta property="og:image" content="http://oqca0721d.bkt.clouddn.com/sjl4nu1503451008.png">
<meta property="og:updated_time" content="2017-08-23T01:17:40.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="更灵活的定位内存地址的方法">
<meta name="twitter:description" content="更灵活的定位内存地址的方法汇编大小写转换12345678910111213141516171819202122232425262728assume cs:code,ds:datadata segmentdb &apos;BaSiC&apos; ;把这个字符串全部变为大写db &apos;iNfOrMaTiOn&apos; ;把这个字符串全部变为小写data endscode segmentstart:  mov ax,data	 ;获取">
<meta name="twitter:image" content="http://oqca0721d.bkt.clouddn.com/wwtpxy1503303934.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 'undefined',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://blog.vimc.cc/2017/08/21/灵活的定位内存地址/">





  <title> 更灵活的定位内存地址的方法 | 你的口袋有什么？ </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?ac9533e5100bee8b75e87a8bb5e51c10";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">你的口袋有什么？</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">Ghost's Blog</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-wisdom">
          <a href="/resume" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br>
            
            简历
          </a>
        </li>
      
        
        <li class="menu-item menu-item-support">
          <a href="/support" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-support"></i> <br>
            
            赞助
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://blog.vimc.cc/2017/08/21/灵活的定位内存地址/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Colorful_Ghost">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="你的口袋有什么？">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
            
            
              
                更灵活的定位内存地址的方法
              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-21T12:01:00+08:00">
                2017-08-21
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/汇编/" itemprop="url" rel="index">
                    <span itemprop="name">汇编</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="更灵活的定位内存地址的方法"><a href="#更灵活的定位内存地址的方法" class="headerlink" title="更灵活的定位内存地址的方法"></a>更灵活的定位内存地址的方法</h2><h3 id="汇编大小写转换"><a href="#汇编大小写转换" class="headerlink" title="汇编大小写转换"></a>汇编大小写转换</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">assume cs:code,ds:data</span><br><span class="line">data segment</span><br><span class="line">db 'BaSiC' ;把这个字符串全部变为大写</span><br><span class="line">db 'iNfOrMaTiOn' ;把这个字符串全部变为小写</span><br><span class="line">data ends</span><br><span class="line">code segment</span><br><span class="line">start:  mov ax,data	 ;获取数据代码段地址</span><br><span class="line">		mov ds,ax 	 ;把代码段地址传送到数据寄存器</span><br><span class="line">		mov bx,0	 ;初始化基地址寄存器  笔记（ds与bx配合，es与dx配合，cx作为计数器）</span><br><span class="line">		mov cx,5</span><br><span class="line">s: 		mov al,[bx]  ;循环体</span><br><span class="line">		and al,11011111b ;b是二进制 对al的值进行位与运算取反</span><br><span class="line">		mov [bx],al</span><br><span class="line">		inc bx</span><br><span class="line">		loop s</span><br><span class="line">		</span><br><span class="line">		mov bx,5	;指向下一个字符串</span><br><span class="line">		mov cx,11	;循环11次</span><br><span class="line">		</span><br><span class="line">s1:		mov al,[bx]</span><br><span class="line">		or al,00100000b	;对al的值进行位或运算取反 </span><br><span class="line">		mov [bx],al</span><br><span class="line">		inc bx</span><br><span class="line">		loop s1</span><br><span class="line">		mov ax,4c00h</span><br><span class="line">		int 21</span><br><span class="line">code ends</span><br><span class="line">end start</span><br></pre></td></tr></table></figure>
<h3 id="使用-bx-idata-的方法优化程序"><a href="#使用-bx-idata-的方法优化程序" class="headerlink" title="使用[bx+idata]的方法优化程序"></a>使用[bx+idata]的方法优化程序</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">assume cs:code,ds:data</span><br><span class="line">data segment</span><br><span class="line">db 'BaSiC'</span><br><span class="line">db 'MinIX'</span><br><span class="line">data ends</span><br><span class="line">code segment</span><br><span class="line">start: mov ax,data</span><br><span class="line">	mov ds,ax</span><br><span class="line">	mov bx,0</span><br><span class="line">	mov cx,5</span><br><span class="line">	s: mov al,[bx]</span><br><span class="line">	and al,11011111b</span><br><span class="line">	mov [bx],al</span><br><span class="line">	</span><br><span class="line">	mov al,[5+bx]</span><br><span class="line">	or al,00100000b</span><br><span class="line">	mov [5+bx],al</span><br><span class="line">	inc bx</span><br><span class="line">	loop s</span><br><span class="line">	mov ax,4c00h</span><br><span class="line">	int 21</span><br><span class="line">code ends</span><br><span class="line">end start</span><br></pre></td></tr></table></figure>
<p><img src="http://oqca0721d.bkt.clouddn.com/wwtpxy1503303934.png" alt="结果"></p>
<h3 id="SI-AND-DI"><a href="#SI-AND-DI" class="headerlink" title="SI AND DI"></a>SI AND DI</h3><p>si和di不能分成2个8位寄存器，也就是不能进行<code>mov al,[si]</code> ,<code>mov al,[di]</code>这样的操作，下面写一个栗子~</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">assume cs:codesm,ds:datasg</span><br><span class="line">datasg segment</span><br><span class="line">db &apos;welcome to masm!&apos;</span><br><span class="line">db &apos;................&apos;</span><br><span class="line">datasg ends</span><br><span class="line"></span><br><span class="line">codesm segment</span><br><span class="line">start: mov ax,datasg</span><br><span class="line">	mov ds,ax</span><br><span class="line">	mov si,0</span><br><span class="line">	mov di,16	</span><br><span class="line">	mov cx,8</span><br><span class="line">	</span><br><span class="line">s:	mov ax,[si]</span><br><span class="line">	mov [di],ax</span><br><span class="line">	add si,2</span><br><span class="line">	add di,2</span><br><span class="line">	loop s</span><br><span class="line">	</span><br><span class="line">	mov ax,4c00h</span><br><span class="line">	int 21</span><br><span class="line">	</span><br><span class="line">codesm ends</span><br><span class="line">end start</span><br></pre></td></tr></table></figure>
<p>上面的代码可以看出si,di递增为2 ，循环次数也缩短了一倍，用16位寄存器进行内存单元之间的数据传送一次复制2 个字节，一共循环八次。</p>
<p>再次优化：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">assume cs:codesm,ds:datasg</span><br><span class="line">datasg segment</span><br><span class="line">db &apos;welcome to masm!&apos;</span><br><span class="line">db &apos;................&apos;</span><br><span class="line">datasg ends</span><br><span class="line"></span><br><span class="line">codesm segment</span><br><span class="line">start: mov ax,datasg</span><br><span class="line">	mov ds,ax</span><br><span class="line">	mov si,0</span><br><span class="line">	mov cx,8</span><br><span class="line">	</span><br><span class="line">s:	mov ax,[si]</span><br><span class="line">	mov [si+16],ax</span><br><span class="line">	inc si,2</span><br><span class="line">	loop s</span><br><span class="line">	</span><br><span class="line">	mov ax,4c00h</span><br><span class="line">	int 21</span><br><span class="line">	</span><br><span class="line">codesm ends</span><br><span class="line">end start</span><br></pre></td></tr></table></figure></p>
<h3 id="将字符串头一个字母改为大写"><a href="#将字符串头一个字母改为大写" class="headerlink" title="将字符串头一个字母改为大写"></a>将字符串头一个字母改为大写</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">assume cs:codesg,ds:datasg</span><br><span class="line">datasg segment</span><br><span class="line">db &apos;1. file         &apos;</span><br><span class="line">db &apos;2. edit         &apos;</span><br><span class="line">db &apos;3. search       &apos;</span><br><span class="line">db &apos;4. view         &apos;</span><br><span class="line">db &apos;5. options      &apos;</span><br><span class="line">db &apos;6. help         &apos;</span><br><span class="line">datasg ends</span><br><span class="line"></span><br><span class="line">codesg segment</span><br><span class="line">start: mov ax,datasg</span><br><span class="line">	mov ds,ax</span><br><span class="line">	mov bx,0</span><br><span class="line">	mov cx,6</span><br><span class="line">	mov si,3</span><br><span class="line"></span><br><span class="line">s:	mov al,[bx][si]</span><br><span class="line">	and al,11011111b</span><br><span class="line">	mov [bx][si],al</span><br><span class="line">	add bx,16</span><br><span class="line">	</span><br><span class="line">	loop s</span><br><span class="line">	mov ax,4c00h</span><br><span class="line">	int 21</span><br><span class="line">codesg ends</span><br><span class="line">end start</span><br></pre></td></tr></table></figure>
<p><img src="http://oqca0721d.bkt.clouddn.com/bj264i1503359790.png" alt="结果"></p>
<h3 id="嵌套循环-把datasg每个单词改为大写"><a href="#嵌套循环-把datasg每个单词改为大写" class="headerlink" title="嵌套循环(把datasg每个单词改为大写)"></a>嵌套循环(把datasg每个单词改为大写)</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">assume cs:codesg,ds:datasg</span><br><span class="line">datasg segment</span><br><span class="line">db &apos;ibm             &apos;</span><br><span class="line">db &apos;dec             &apos;</span><br><span class="line">db &apos;dos             &apos;</span><br><span class="line">db &apos;vax             &apos;</span><br><span class="line">datasg ends</span><br><span class="line"></span><br><span class="line">codesg segment</span><br><span class="line">start: mov ax,datasg</span><br><span class="line">	mov ds,ax</span><br><span class="line">	mov bx,0</span><br><span class="line">	mov cx,4	;外层循环4次</span><br><span class="line">s:	mov dx,cx	;因为进行下一次循环不能保存CX利用dx暂存</span><br><span class="line">	mov si,0</span><br><span class="line">	mov cx,3	;内层循环3次</span><br><span class="line">s0:	mov al,[bx][si]	</span><br><span class="line">	and al,11011111b</span><br><span class="line">	mov [bx][si],al</span><br><span class="line">	inc si</span><br><span class="line">loop s0</span><br><span class="line">	add bx,16	;每次内循环完成偏移到下一段字符串</span><br><span class="line">	mov cx,dx</span><br><span class="line">loop s</span><br><span class="line">	mov ax,4c00h</span><br><span class="line">	int 21</span><br><span class="line">	</span><br><span class="line">codesg ends</span><br><span class="line">end start</span><br></pre></td></tr></table></figure>
<p>讲道理汇编的嵌套循环有点不习惯….<br>这只是2层嵌套 如果更多嵌套则寄存器不够用，这时候我们就不能用寄存器来暂存CX了</p>
<h3 id="用栈来处理cx缓存问题"><a href="#用栈来处理cx缓存问题" class="headerlink" title="用栈来处理cx缓存问题"></a>用栈来处理cx缓存问题</h3><p>将datasg数据段每个单词前4个字幕改为大写</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">assume cs:codesg,ds:datasg,ss:stacksg</span><br><span class="line">datasg segment</span><br><span class="line">db &apos;1. display      &apos;</span><br><span class="line">db &apos;2. brows        &apos;</span><br><span class="line">db &apos;3. replace      &apos;</span><br><span class="line">db &apos;4. modify       &apos;</span><br><span class="line">datasg ends</span><br><span class="line"></span><br><span class="line">stacksg segment</span><br><span class="line">dw 0,0,0,0,0,0,0,0</span><br><span class="line">stacksg ends</span><br><span class="line"></span><br><span class="line">codesg segment</span><br><span class="line">start: mov ax,datasg</span><br><span class="line">	mov ds,ax</span><br><span class="line">	mov bx,0</span><br><span class="line">	mov cx,4</span><br><span class="line">	</span><br><span class="line">i0: mov ax,[bx]</span><br><span class="line">	push cx				;保存外层循环次数</span><br><span class="line">	mov cx,2			;初始化内层循环次数</span><br><span class="line">	mov di,0</span><br><span class="line">i1:	mov ax,[bx][3][di]	; (ax)=(bx)+(di)+3</span><br><span class="line">	and al,11011111b	; 因为di是16位寄存器所以要利用把ax拆开与运算</span><br><span class="line">	and ah,11011111b	;这样做的目的是为了减少循环次数</span><br><span class="line">	mov [bx][3][di],ax	;把处理后的ax传送到原来的位置</span><br><span class="line">	add di,2			;(di)=(di)+2  di地址偏移2个字单元</span><br><span class="line">	loop i1</span><br><span class="line"></span><br><span class="line">	add bx,16			;把基地址便宜到下一行字符串</span><br><span class="line">	pop cx				;把刚才push的cx出栈</span><br><span class="line">	</span><br><span class="line">	loop i0</span><br><span class="line">	mov ax,4c00h</span><br><span class="line">	int 21</span><br><span class="line">	</span><br><span class="line">codesg ends</span><br><span class="line">end start</span><br></pre></td></tr></table></figure>
<p><img src="http://oqca0721d.bkt.clouddn.com/sjl4nu1503451008.png" alt="实验6"></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/笔记/" rel="tag"># 笔记</a>
          
            <a href="/tags/汇编/" rel="tag"># 汇编</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/08/17/汇编Loop和-bx-的联合应用/" rel="next" title="汇编Loop和[bx]的联合应用">
                <i class="fa fa-chevron-left"></i> 汇编Loop和[bx]的联合应用
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/08/27/寻址方式在结构化数据访问/" rel="prev" title="寻址方式在结构化数据访问">
                寻址方式在结构化数据访问 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8yOTUyMy82MDkx"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image" src="/images/avatar.gif" alt="Colorful_Ghost">
          <p class="site-author-name" itemprop="name">Colorful_Ghost</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
           
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">16</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="http://steamcommunity.com/id/233000/" target="_blank" title="Steam">
                  
                    <i class="fa fa-fw fa-steam"></i>
                  
                  Steam
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://wpa.qq.com/msgrd?v=3&uin=815666528&site=qq&menu=yes" target="_blank" title="QQ">
                  
                    <i class="fa fa-fw fa-qq"></i>
                  
                  QQ
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://t.me/Colorful_Ghost" target="_blank" title="Telegram">
                  
                    <i class="fa fa-fw fa-telegram"></i>
                  
                  Telegram
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-block">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.chaosgoo.com" title="Chaosgoo" target="_blank">Chaosgoo</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#更灵活的定位内存地址的方法"><span class="nav-number">1.</span> <span class="nav-text">更灵活的定位内存地址的方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#汇编大小写转换"><span class="nav-number">1.1.</span> <span class="nav-text">汇编大小写转换</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用-bx-idata-的方法优化程序"><span class="nav-number">1.2.</span> <span class="nav-text">使用[bx+idata]的方法优化程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SI-AND-DI"><span class="nav-number">1.3.</span> <span class="nav-text">SI AND DI</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#将字符串头一个字母改为大写"><span class="nav-number">1.4.</span> <span class="nav-text">将字符串头一个字母改为大写</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#嵌套循环-把datasg每个单词改为大写"><span class="nav-number">1.5.</span> <span class="nav-text">嵌套循环(把datasg每个单词改为大写)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#用栈来处理cx缓存问题"><span class="nav-number">1.6.</span> <span class="nav-text">用栈来处理cx缓存问题</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Colorful_Ghost</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

  <p>Hosted by <a href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a></p>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  






  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  


  




	





  





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  






  





  

  

  

  

</body>
</html>
